package com.example;

import com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class DbUtils {
    static SqlSessionFactory sessionFactory = null;
    static {
        String resource = "my.xml";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);
        } catch (IOException e) {
            e.printStackTrace();
        }
        sessionFactory = new MybatisSqlSessionFactoryBuilder().build(inputStream);
    }

    public static void addMapper(Class mapperClass){
        sessionFactory.getConfiguration().addMapper(mapperClass);
    }


    public static void main(String[] args) {
        DbUtils.addMapper(UserMapper.class);
        List<User> list = Db.list(User.class);
        System.out.println(list);
    }


}
